Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build hook spec #955

Merged
merged 12 commits into from
Feb 9, 2024
Merged

Build hook spec #955

merged 12 commits into from
Feb 9, 2024

Conversation

dcharkes
Copy link
Collaborator

To be followed up by a v2.md

Copy link

PR Health

Breaking changes ✔️

Details
Package Change Current Version New Version Needed Version Looking good?
native_assets_builder None 0.3.2 0.3.2 0.3.2 ✔️

Changelog Entry ✔️

Details
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

Coverage ✔️

Details
File Coverage

This check for test coverage is informational (issues shown here will not fail the PR).

License Headers ✔️

Details
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/ffi/example/main.dart
pkgs/ffigen/example/libclang-example/generated_bindings.dart
pkgs/ffigen/example/objective_c/avf_audio_bindings.dart
pkgs/ffigen/example/shared_bindings/generate.dart
pkgs/ffigen/example/shared_bindings/lib/generated/a_gen.dart
pkgs/ffigen/example/shared_bindings/lib/generated/a_shared_b_gen.dart
pkgs/ffigen/example/shared_bindings/lib/generated/base_gen.dart
pkgs/ffigen/example/simple/generated_bindings.dart
pkgs/ffigen/example/swift/swift_api_bindings.dart
pkgs/ffigen/lib/src/config_provider/config_spec.dart
pkgs/ffigen/lib/src/header_parser/clang_bindings/clang_bindings.dart
pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_decl_collision_bindings.dart
pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart
pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_type_name_collision_bindings.dart
pkgs/ffigen/test/collision_tests/expected_bindings/_expected_reserved_keyword_collision_bindings.dart
pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_comment_markup_bindings.dart
pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_dart_handle_bindings.dart
pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_forward_decl_bindings.dart
pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart
pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_imported_types_bindings.dart
pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_native_func_typedef_bindings.dart
pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_opaque_dependencies_bindings.dart
pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_packed_structs_bindings.dart
pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_regress_384_bindings.dart
pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_struct_fptr_fields_bindings.dart
pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart
pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_unions_bindings.dart
pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_varargs_bindings.dart
pkgs/ffigen/test/large_integration_tests/_expected_cjson_bindings.dart
pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart
pkgs/ffigen/test/large_integration_tests/_expected_sqlite_bindings.dart
pkgs/ffigen/test/native_test/_expected_native_test_bindings.dart
pkgs/jni/lib/src/lang/jcharacter.dart
pkgs/jni/lib/src/third_party/generated_bindings.dart
pkgs/jni/lib/src/third_party/global_env_extensions.dart
pkgs/jni/lib/src/third_party/jni_bindings_generated.dart
pkgs/jnigen/android_test_runner/lib/main.dart
pkgs/jnigen/example/in_app_java/lib/android_utils.dart
pkgs/jnigen/example/kotlin_plugin/example/lib/main.dart
pkgs/jnigen/example/kotlin_plugin/lib/kotlin_bindings.dart
pkgs/jnigen/example/kotlin_plugin/lib/kotlin_plugin.dart
pkgs/jnigen/example/pdfbox_plugin/lib/pdfbox_plugin.dart
pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/_init.dart
pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocument.dart
pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/PDDocumentInformation.dart
pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/pdmodel/_package.dart
pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/text/PDFTextStripper.dart
pkgs/jnigen/example/pdfbox_plugin/lib/src/third_party/org/apache/pdfbox/text/_package.dart
pkgs/jnigen/lib/src/bindings/descriptor.dart
pkgs/jnigen/lib/src/elements/elements.g.dart
pkgs/jnigen/test/jackson_core_test/third_party/c_based/dart_bindings/com/fasterxml/jackson/core/_package.dart
pkgs/jnigen/test/jackson_core_test/third_party/dart_only/dart_bindings/com/fasterxml/jackson/core/_package.dart
pkgs/jnigen/tool/command_runner.dart
tools/check_pubspec_overrides.dart
tools/delete_pubspec_overrides.dart

Package publish validation ✔️

Details
Package Version Status
package:ffi 2.1.2 already published at pub.dev
package:ffigen 12.0.0-wip WIP (no publish necessary)
package:jni 0.8.0-wip WIP (no publish necessary)
package:jnigen 0.8.0-wip WIP (no publish necessary)
package:native_assets_builder 0.3.2 already published at pub.dev
package:native_assets_cli 0.4.2 already published at pub.dev
package:native_toolchain_c 0.3.5-wip WIP (no publish necessary)

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@dcharkes dcharkes requested a review from mosuem January 25, 2024 16:51

Currently, all such assets are dynamic libraries.

An asset must have an `assetId`. Dart code that uses an asset, references the asset using the `assetId`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in the other items: You probably mean the metadata must contain? Also, what does using mean? I assume just referencing, as an asset is a file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we have conflated the Asset class that is metadata, and the file. This probs requires a full rewrite.

Since we also have a "metadata" field in the build input and build output, we shoudl probably refrain from calling everything that is not the file metadata. Maybe we should call the file the "asset file".


An asset must have an `assetId`. Dart code that uses an asset, references the asset using the `assetId`.

An asset must have a target os and target architecture. When accessing the asset at runtime, the asset for the current os and architecture is accessed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought there is not necessarily a target architecture in dry run mode?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not as input, but there is for the output. We should probably fix that in v2.

An asset must specify a path type for dynamic linking.

* `absolute` paths are absolute paths in the output dir (see below).
* `system` paths are expected to resolve on the target machine PATH. In this case the asset is not a file but only metadata.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case the asset is not a file but only metadata. well that is not really agreeing with what an asset is. I would update the definition above.


* `absolute` paths are absolute paths in the output dir (see below).
* `system` paths are expected to resolve on the target machine PATH. In this case the asset is not a file but only metadata.
* `process` "paths" have no path, symbols are resolved in the current process. In this case the asset is not a file but only metadata.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"paths" have no path - What does this mean? What are paths? What are symbols - assets are files, right?

Copy link
Collaborator Author

@dcharkes dcharkes Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah so code assets are already much more involved than "a file". Code assets can be metadata only. And some variants of that metadata do not require any path.

path_type is probably not the right name.

Maybe it should be dynamic_library_type. But the executable and process one don't even have a dynamic library.

So then it should be dynamic_linking_type. This also sounds weird, because the linking always is the same in a way.

Maybe it should be dynamic_resolution_type. That gets closer. But the problem here is that we're also abstracting over the resolution partially. Dart and Flutter repackage dynamic libraries. So in this protocol for absolute paths, it's the absolute path at the point of this protocol. But for system paths, process, and executable the metadata gets passed in unmodified.

So then it should maybe be something like:

- asset_id: ...
  dynamic_resolution:
    type: bundled_dylib
    # no path here, because that will be decided by Flutter/Dart when making the bundle.
  path: ... # Not nested in dynamic_resolution, it's the path for the protocol.
- asset_id: ...
  dynamic_resolution:
    type: system
    path: ... # Nested in dynamic_resolution, it's the metadata to be passed into linking.
- asset_id: ...
  dynamic_resolution:
    type: process
- asset_id: ...
  dynamic_resolution:
    type: executable

wdyt?

* Write assets into `out_dir` from `build_config.yaml`.
* If `dry_run: true` in `build_config.yaml`, then this may be skipped.
* Filename are unrelated to `assetId`.
* Arbitrary file names are fine, `build_output.yaml` will map `assetId` to files.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file names of the assets don't really matter. It could be file1.foo, file2.foo, file3.foo. Because the only way assets are accessed from Dart code is through their assetId.

However, we do want to have to files written to disk rather than having a buffer of bytes for files, because quite often the files are produces by an external Process call or for data assets already in your package.

* If `dry_run: true` in `build_config.yaml`, then this may be skipped.
* Filename are unrelated to `assetId`.
* Arbitrary file names are fine, `build_output.yaml` will map `assetId` to files.
* MUST avoid file name `build_output.yaml`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a name for an asset?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you write your asset to out_dir/build_output.yaml it's going to fail to write build_output.yaml

Maybe in v2 we should consider writing the assets somewhere else than the build output.

* MUST avoid file name `build_output.yaml`.
* Write `build_output.yaml` into `out_dir` (from `build_config.yaml`).
* This maps `assetId` to assets previous written in `out_dir`.
* There may be multiple assets for a given `assetId` depending on
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to add something about the uniqueness of an assetId - this was unclear in an earlier review comment as well.

@mosuem
Copy link
Member

mosuem commented Feb 2, 2024

@dcharkes I pushed some suggestions, if you want to take a look.

Copy link
Collaborator Author

@dcharkes dcharkes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mosuem I like it!

@dcharkes
Copy link
Collaborator Author

dcharkes commented Feb 9, 2024

Okay, I think this is in a good enough shape. I'll merge this and we can do more edits later. 👍

@auto-submit auto-submit bot merged commit cb9bd7e into main Feb 9, 2024
34 checks passed
@auto-submit auto-submit bot deleted the build-hook-spec branch February 9, 2024 13:50
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Feb 13, 2024
Revisions updated by `dart tools/rev_sdk_deps.dart`.

crypto (https://github.com/dart-lang/crypto/compare/c954015..f059196):
  f059196  2024-02-08  Kevin Moore  Test dart2wasm (dart-archive/crypto#162)

dartdoc (https://github.com/dart-lang/dartdoc/compare/457c34e..f152c01):
  f152c013  2024-02-08  Sam Rawlins  Tidy spacing in templates (dart-lang/dartdoc#3652)
  d0c53b9f  2024-02-07  Sam Rawlins  Change all late final Iterable fields to Lists (dart-lang/dartdoc#3649)
  8c9c7790  2024-02-06  Sam Rawlins  Remove unnecessary ExtensionTarget mixin (dart-lang/dartdoc#3648)
  d2f90c5a  2024-02-06  Sam Rawlins  Fix the 'serve testing-package' task to generate docs (dart-lang/dartdoc#3647)

ecosystem (https://github.com/dart-lang/ecosystem/compare/7d8ec47..3e4f286):
  3e4f286  2024-02-08  Moritz  Add ignore flag for `publish.yaml` (dart-lang/ecosystem#237)

lints (https://github.com/dart-lang/lints/compare/90a61e4..ead7708):
  ead7708  2024-02-08  Devon Carew  add library_annotations; remove package_prefixed_library_names (dart-lang/lints#179)

native (https://github.com/dart-lang/native/compare/876f9a1..cb9bd7e):
  cb9bd7ef  2024-02-09  Daco Harkes  Build hook spec (dart-lang/native#955)

sse (https://github.com/dart-lang/sse/compare/e483b14..af7d8d0):
  af7d8d0  2024-02-09  Ilya Yanok  Make `SseConnection` extend `StreamChannelMixin<String>` (dart-archive/sse#102)

Change-Id: I2e85dbfae00eea8de7b6f7efce1993bf00e243f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352046
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
Auto-Submit: Devon Carew <devoncarew@google.com>
auto-submit bot pushed a commit that referenced this pull request Feb 14, 2024
There are multiple differences between the `native_assets.yaml` that is embedded in the kernel file and the `build_output.yaml -> assets`. 

* Based on the discussions on #955 and #946, it is clear that the `path` for assets should be in `Asset`, not in `AssetPath` for the file-path the asset has after the `build.dart` run. When the embedders (Flutter/Dart) embed the native assets mapping then the `path`s start representing the path on the system where the Dart/Flutter app is running. This should be embedded in the path-type there.
* The kernel info does not contain link mode (currently), as static linking is not supported. It's not clear that if we support static linking whether any information should be embedded in the kernel info at all.
* The native_assets.yaml for the kernel file is laid out for easy lookup at runtime (keyed on Target).
* We want to change the `Asset`s to output OS and Architecture instead of Target.

Therefore we should not share the data structure between `Asset`s and `KernelAsset`s (new name for the entries that are embedded via native_assets.yaml in a kernel file.)

This means that `dartdev` and `flutter_tools` will have to start converting `Asset`s to `KernelAsset`s when making the `native_assets.yaml` file. Therefore this is a breaking change and will have to be rolled into Dart and flutter/flutter manually.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants